//index.js
//获取应用实例
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    phone: '',
    content: '',
  },
  //监听输入
  bindNameInput: function (e) {
    this.data.name = e.detail.value;
  },
  bindPhoneInput: function (e) {
    this.data.phone = e.detail.value;
  },
  bindContentInput: function (e) {
    this.data.content = e.detail.value;
  },
  //分享
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '铂爵影楼实景装修设计',
      path: 'pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  //监听FORM值
  bindSubmit: function (e) {
    //验证是否填写完善必要信息
    if (this.data.name == '' || this.data.phone == '') {
      wx.showModal({
        title: '提示',
        content: '请填写必要信息',
        showCancel: false
      });
      return;
    }
    var formData = this.data;
    var that = this;
    this.setData({
      buttonLoading: true
    })

    //提交数据  
    wx.request({
      url: getApp().globalData.baseURL + '/cmsLeaveMessage/add/api', //仅为示例，并非真实的接口地址
      data: formData,
      header: {
        'content-type': 'application/json', // 默认值
      },
      success: function (res) {
        that.setData({
          buttonLoading: false
        });
        console.log(res.data)
        const result = res.data
        if (result.result == true) {
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 3000
          })
        }else{
          wx.showToast({
          title: '提交失败',
          icon: 'fail',
          duration: 3000
        })
        }

      }
    })
   
  },
  onLoad: function () {

  },

  onShow: function () {
  },
})